package br.com.management.mentor.model.repositories;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import com.mysema.query.jpa.impl.JPAQuery;

import br.com.management.mentor.model.beans.Product;
import br.com.management.mentor.model.beans.QProduct;

public class ProductRepository {

	private QProduct qProduct = QProduct.product;

	@Autowired
	private EntityManagerFactory emf;

	List<Product> autocomplete( String description ) {
		EntityManager em = emf.createEntityManager();
		try {
			JPAQuery query = new JPAQuery( em );
			return query.from( qProduct ).where( qProduct.description.eq( description ) ).list( qProduct );
		} finally {
			if ( em != null ) em.close();
		}
	}

}
